Conversion between DMS and decimal degrees:
\[DD = D + \frac{M}{60} + \frac{S}{3600}\]
Examples:
GeoPandas: Python package that extends pandas to represent geographic objects as GeoDataFrames
Key column: geometry, which represents the geometry type of the data (point, line, or polygon) and the sequence of coordinates
gp.GeoDataFrame(): function used to generate the GeoDataFrame, which can take an existing pandas DataFrame as its first argument
geometry: how to represent the data as a geographic object. We use the gp.points_from_xy() function here to “make” the geometry from existing Longitude and Latitude columns.crs: a code that specifies the dataset’s coordinate reference system. Most coordinate systems can be represented by 4- or 5-digit codes (see https://spatialreference.org/)import contextily as ctx
# "Project" to Web Mercator, used by tiled mapping services
sbgeo2 = sbgeo.to_crs(3857)
# Use the basemap function found at https://share.cocalc.com/share/56cef78b3fda5e0338c2da71b222e6b275a9193e/contextily.ipynb?viewer=share
def add_basemap(ax, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png'):
xmin, xmax, ymin, ymax = ax.axis()
basemap, extent = ctx.bounds2img(xmin, ymin, xmax, ymax, zoom=zoom, url=url)
ax.imshow(basemap, extent=extent, interpolation='bilinear')
# restore original x/y limits
ax.axis((xmin, xmax, ymin, ymax))Extension to the JSON format that encodes geographic coordinates for datasets
import pandas as pd, seaborn as sns, matplotlib.pyplot as plt
sns.set(style="whitegrid", font_scale = 1.3)
df = pd.read_csv("http://personal.tcu.edu/kylewalker/mexico.csv")
plt.figure(figsize = (10, 8))
p = sns.stripplot(data = df.sort_values('pri10', ascending = False),
x = 'pri10', y = 'name', palette = "RdPu_d",
orient = 'h', size = 8)
p.set(xlabel = "% of workforce in primary sector",
xlim = (0, 50), ylabel = "")
p.axes.xaxis.grid(False)
p.axes.yaxis.grid(True)
sns.despine(left = True, bottom = True)